package com.ck.express.db

import android.content.Context
import androidx.room.Room
import com.ck.express.db.dao.FailedDeliveryRequestDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

    @Provides
    @Singleton
    fun provideDatabase(@ApplicationContext context: Context): ExpressDatabase {
        return Room.databaseBuilder(
            context,
            ExpressDatabase::class.java,
            "express.db"
        )
            // 不建议 fallbackToDestructiveMigration()，用 addMigrations(...) 替代
            .build()
    }

    @Provides
    fun provideFailedDao(db: ExpressDatabase): FailedDeliveryRequestDao {
        return db.failedDeliveryRequestDao()
    }
}
